#ifndef __SINGLE_LIST_GP_H__
#define __SINGLE_LIST_GP_H__

#include <stdlib.h>
#include <stdbool.h>
// 没有哨兵的list
typedef struct list_node {
    struct list_node *next;
    void *value;
}list_node;

typedef struct linked_list {
    list_node *head;
    size_t length;
    size_t typesize;

    void (*dup)(void *, void *);
    int (*match)(void *, void *);
    void (*free)(void *);

}linked_list;

#define list_set_dup_method(l, m) ((l)->dup = (m))
#define list_set_free_method(l, m) ((l)->free = (m))
#define list_set_match_method(l, m) ((l)->match = (m))

#define list_get_dup_method(l) ((l)->dup)
#define list_get_free_method(l) ((l)->free)
#define list_get_match_method(l) ((l)->match)

linked_list * list_create();
void list_release(linked_list *list); //释放链表
void list_empty(linked_list *list); //清空链表
linked_list *list_add_node_head(linked_list *list, void *value);
linked_list *list_add_node_tail(linked_list *list, void *value);
// 注意对头节点的处理
//linked_list *list_insert_node(linked_list *list, list_node *old_node, void *value, bool after); 
void list_del_node(linked_list *list, list_node *node);//指针的对比就可以

list_node *list_search_key(linked_list *list, void *key);//查找某个值
list_node *list_index(linked_list *list, int index);
linked_list * list_rewind(linked_list *list); //反转

size_t list_length(linked_list *list);

#endif //!__SINGLE_LIST_GP_H__

